package com.java.study.boot;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yuansheng.xu
 */
@SpringBootApplication
public class BootApplication {

    public static void main(String[] args) {
        SpringApplication.run(BootApplication.class, args);
    }


    @RestController
    public static class HelloController {

        @Autowired
        BeanFactory beanFactory;

        @Autowired
        Environment environment;

        @Autowired
        TestInterface testInterface;

        @RequestMapping("getEnv")
        public Object testLog() {
            return environment;
        }

        @RequestMapping("hello")
        public String hello() {
            return "hello world!" + testInterface.test();
        }

        @RequestMapping("nationalToIndex")
        public String nationalToIndex() {
            return "hello world!" + testInterface.test();
        }

        @GetMapping("login")
        public void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
            response.sendRedirect("/nationalToIndex");
        }
    }

}
